#ifndef CTETRABUFFER_H
#define CTETRABUFFER_H

/*
All CTetras must be in a CTetraBuffer to be included in simulation.
*/

#include <stdlib.h>

#include "ISceneNode.h"
#include "CTetra.h"
#include "IGameObject.h"

//using namespace irr;
//using namespace MarCore;

class btRigidBody;

namespace MarCore
{

namespace Tetra
{

class CTetra;

enum ETETRA_BUFFER_MODE
{

    ERIGID_DFRM,

    ERIGID,

    ESTATIC_DFRM,

    ESTATIC,

    ECOUNT

};

typedef core::array<CTetra*> CTetraArray;

class CTetraBuffer : public IGameObject
{

    ///!
    ///@todo ? IPhysicsGameObject
    //btRigidBody* bt_body; // physics component, will be derived custom class

    scene::ISceneNode* irr_node; //graphics component, will be derived custom class

    CTetraArray* tetra_array; //the buffer itself, an array of pointers

    bool active; //active for simulation? Kind of a main on-off switch, needed?

    ETETRA_BUFFER_MODE mode;

    bool needs_Update; //flags for update of update to bullet mesh and irrlicht node

public:

    //! Default Constructor
    CTetraBuffer();

    //! Constructor
    CTetraBuffer( IGameObject* crank, CGameObjectArray* rod );

    //! Constructor
    CTetraBuffer( const CTetraArray& tetras, IGameObject* crank, CGameObjectArray* rod );

    //! Destructor
    ~CTetraBuffer();

    //! Adds CTetra to buffer
    void addCTetra( const CTetra& tetra );

    //! Returns pointer to CTetra at index i
    CTetra* getCTetra( u32 i );

    //! Removes pointer to CTetra at index i

    //! Removes the CTetra from the buffer.
    void deleteFromBuffer( CTetra* tetra );

    ///@todo remove this, this is bullet work
    //! Simulates one step.
    //void stepVQSimulation();

    //! Ques this to be taken into bullet dynamics world
    void passToBullet();

    //! Ques this to be taken out of bullet dynamics world
    void removeFromBullet();

    //! Returns 1 if positive 0 if negative
    bool needsUpdate();

}; //end class CTetraBuffer

}; //end namespace Tetra
}; //end namespace MarCore

#endif //CTETRABUFFER_H
